---简单的数据对象池
---@class GOAPObjPool
---@field activeDic table<type,class>
---@field inactiveDic table<type,class>
GOAPObjPool = {}

function GOAPObjPool:Spwan(type,...)
    if self.inactiveDic == nil then
        self.inactiveDic = {}
    end
    if self.activeDic == nil then
        self.activeDic = {}
    end
    local obj = nil
    if self.inactiveDic[type] ~= nil and table.count(self.inactiveDic[type]) > 0 then
        for k, v in pairs(self.inactiveDic[type]) do
            obj = self.inactiveDic[type][1];
            self.inactiveDic[type][k] = nil;
            break;
        end
    else
        self.inactiveDic[type] = {}
        obj = GOAPObjPool:SpwanNew(type,...);
    end
    if self.activeDic[type] == nil then
        self.activeDic[type] = {};
    end
    self.activeDic[type][obj] = true;
    return obj;
end

function GOAPObjPool:SpwanNew(type,...)
    return type.new(...);
end

function GOAPObjPool:Despawn(type,obj)
    if self.inactiveDic == nil then
        self.inactiveDic = {}
    end
    if self.activeDic == nil then
        self.activeDic = {}
    end
    if self.activeDic[type] ~= nil and self.activeDic[type][obj] ~= nil then
        self.inactiveDic[type][obj] = true;
        self.activeDic[type][obj] = nil;
    else
        Debug.LogError(tostring(type).."此类型对象不存在缓存池中")
    end
end

function GOAPObjPool:CleanPool()
    for k, v in pairs(self.activeDic) do
        v:Release();
    end
    for k, v in pairs(self.inactiveDic) do
        v:Release();
    end
    self.activeDic = {}
    self.inactiveDic = {}
end